package org.neuedu.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

import org.neuedu.bean.*;
import org.neuedu.service.UserService;
import org.neuedu.service.UserServiceImpl;

@WebServlet(name = "ForwardHomeServlet",urlPatterns = "/home")
public class ForwardhomeServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = (User)request.getSession().getAttribute("fly_user");
        UserService service = new UserServiceImpl();
        List<Article> list1 = service.userArticle(user.getId());
        List<Reply> list2 = service.userReply(user.getId());
        request.setAttribute("article_list",list1);
        request.setAttribute("reply_list",list2);
        request.getRequestDispatcher("/WEB-INF/jsp/user/home.jsp").forward(request,response);
    }
}

